package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.entity.CustomerOrder;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.CustomerOrdersMapper;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.CustomerOrdersService;
import com.zzyl.vo.CustomerOrdersVo;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CustomerOrdersImpl implements CustomerOrdersService {

    @Autowired
    private CustomerOrdersMapper CustomerOrdersMapper;


    /**
     * 根据ID查询
     *
     * @param id ID
     * @return
     */
    @Override
    public CustomerOrdersVo findById(Long id) {
        CustomerOrdersVo customerOrdersVo = new CustomerOrdersVo();
        CustomerOrder customerOrders = CustomerOrdersMapper.findById(id);
        BeanUtils.copyProperties(customerOrders, customerOrdersVo);
        return customerOrdersVo;
    }

    /**
     * 条件分页查询
     *
     * @param name     项目名称
     * @param pageNum  当前页面
     * @param pageSize 每页条数
     * @param status   状态
     * @return
     */
    @Override
    public PageResponse<CustomerOrdersVo> list(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<CustomerOrdersVo> page =CustomerOrdersMapper.list(name, status);
        PageResponse<CustomerOrdersVo> pageResponse=new PageResponse<>();
        pageResponse.setPage(pageNum);
        pageResponse.setPageSize(pageSize);
        pageResponse.setTotal(page.getTotal());
        pageResponse.setRecords(page.getResult());
        return pageResponse;
    }
}
